﻿using System;
using System.Threading;
public struct Time
{
    public int hour, minute, second;
}
public class Args
{
    public Time t;
    public Args(Time x) { t = x; }
}
public delegate void AlarmHandler(object sender, Args args);
public delegate void TickHandler(object sender, Args args);
class Clock
{
    public event AlarmHandler Alarm;
    public event TickHandler Tick;
    public Time t;
    public Time ala;
    public Clock(Time a, Time b) { t = a; ala = b; }
    public void tick()
    {
        t.second++;
        if (t.second >= 60)
        {
            t.second = 0;
            t.minute++;
            if (t.minute >= 60)
            {
                t.minute = 0;
                t.hour++;
                if (t.hour >= 25) t.hour = 1;
            }
        }
        Console.WriteLine("TICK! Now is {0}:{1}:{2}", t.hour.ToString().PadLeft(2, '0'), t.minute.ToString().PadLeft(2, '0'), t.second.ToString().PadLeft(2, '0'));
        Args arg = new Args(t);
        Tick(this, arg);
        if (t.hour == ala.hour && t.minute == ala.minute && t.second == ala.second)
        {
            alarm();
        }
    }
    public void alarm()
    {
        Console.WriteLine("ALARM! Now is {0}:{1}:{2}", t.hour.ToString().PadLeft(2, '0'), t.minute.ToString().PadLeft(2, '0'), t.second.ToString().PadLeft(2, '0'));
        Args arg = new Args(t);
        Alarm(this, arg);
    }
}
namespace _2_Clock
{
    class Program
    {
        static void tic(object sender, Args args)
        {
            Console.WriteLine("时间开始流动");
        }
        static void ala(object sender, Args args)
        {
            Console.WriteLine("可以起床了嗷!!!!!!!!!!");
        }
        static void Main(string[] args)
        {
            int a, b, c, d, e, f;
            Console.WriteLine("请输入现在的时分秒和闹钟的时分秒");
            a = int.Parse(Console.ReadLine());
            b = int.Parse(Console.ReadLine());
            c = int.Parse(Console.ReadLine());
            d = int.Parse(Console.ReadLine());
            e = int.Parse(Console.ReadLine());
            f = int.Parse(Console.ReadLine());
            Time Now, Ala;
            Now.hour = a; Now.minute = b; Now.second = c;
            Ala.hour = d; Ala.minute = e; Ala.second = f;
            Clock clock1 = new Clock(Now, Ala);
            clock1.Tick += tic;
            clock1.Alarm += ala;
            while (true)
            {
                Thread.Sleep(1000);
                clock1.tick();
            }
        }
    }
}
